package com.sanjiahantang.youjiaclient.module.money.models.impl;

import android.content.Context;

import com.sanjiahantang.youjiaclient.base.BaseBean;
import com.sanjiahantang.youjiaclient.base.CallBack;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.http.BaseDelegate;
import com.sanjiahantang.youjiaclient.http.OkHttpClientManager;
import com.sanjiahantang.youjiaclient.module.common.beans.StringBean;
import com.sanjiahantang.youjiaclient.module.money.beans.BankCardBean;
import com.sanjiahantang.youjiaclient.module.money.models.IMoneyModel;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by zy on 2018/3/23.
 */

public class MoneyModel implements IMoneyModel {
    @Override
    public void updateDefaultBankCard(final Context context, Map<String, String> map, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/bank/customer/updateDefaultBankCard",
                map, new BaseDelegate.ResultCallback<BaseBean>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(BaseBean response, Object tag) {
                        callBack.onSuccess(response, context, tag);
                    }
                });
    }

    @Override
    public void addBankInfo(final Context context, Map<String, Object> map, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/bank/customer/addBankCardInfo", map, new BaseDelegate.ResultCallback<StringBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringBean response, Object tag) {
                callBack.onSuccess(response, context, tag);

            }
        });
    }

    @Override
    public void checkBankListInfo(final Context context, Map<String, Object> map, final CallBack<BankCardBean.CardList> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/money/bank/customer/searchBankCardInfo", map, new BaseDelegate.ResultCallback<BankCardBean.CardList>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(BankCardBean.CardList response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }

    @Override
    public void cardBindingSMS(final Context context, Map<String, String> map, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/money/bank/customer/cardBindingSMS", map, new BaseDelegate.ResultCallback<StringBean>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringBean response, Object tag) {
                callBack.onSuccess(response, context, tag);
            }
        });
    }
}
